<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<script type="text/JavaScript" src="resources/js/cloud-zoom.1.0.2.min.js"></script>
<c:forEach items='${products}' var='product'>
<table class='productTable'>
	<tr>
		<td class='td40'>
			<c:forEach items="${photoAvailable}" var="item">
				<c:if test="${item.key == product.EAN_UCC_13}">
					<c:choose>
						<c:when test="${item.value == true}">
							<a href='resources/images/producten/${product.EAN_UCC_13}/big.jpg' class = 'cloud-zoom' id='zoom1' rel='adjustX: 10, adjustY:-4'>
								<img src='resources/images/producten/${product.EAN_UCC_13}/small.jpg' alt=''/>
							</a>
						</c:when>
						<c:when test="${item.value == false}">
							<img src='resources/images/producten/no_photo/no_photo.jpg' alt=''/>
						</c:when>
					</c:choose>
				</c:if>
			</c:forEach>
		</td>
		<td class='td60'>
			<div class='productOmschrijving'>
				<span class='notebookTitel'>
					${product.name}
				</span>
				<br/>
				<br/>
				${product.description}
			</div>
		</td>
	</tr>
	<tr>
		<td class='td40'>
			<div class='center'>
			<span class='rating'>
				<c:set var='counter' value='0'/>
				<c:set var='totaal' value='0'/>
				<c:forEach items='${ratings}' var='rating'>
					<c:if test='${rating.EAN_UCC_13 == product.EAN_UCC_13}'>
						<c:set var='counter' value='${counter + 1}' />
						<c:set var='totaal' value='${totaal + rating.value}' />
					</c:if>
				</c:forEach>
				<c:choose>
					<c:when test='${counter != 0}'>
						<c:set var='gemiddelde' value='${totaal / counter}' />
					</c:when>
					<c:when test='${counter == 0}'>
						<c:set var='gemiddelde' value='0' />
					</c:when>
				</c:choose>
				<c:forEach var='i' begin='1' end='5'>
					<c:choose>
						<c:when test='${gemiddelde >= 1}'>
							<img src='resources/images/producten/rating/star.png' alt='' />
							<c:set var='gemiddelde' value='${gemiddelde - 1}' />
						</c:when>
						<c:when test='${gemiddelde > 0}'>
							<img src='resources/images/producten/rating/halfstar.png' alt='' />
							<c:set var='gemiddelde' value='0' />
						</c:when>
						<c:otherwise>
							<img src='resources/images/producten/rating/blankstar.png' alt='' />
						</c:otherwise>
					</c:choose>
				</c:forEach>
			</span>
				<br/>
				<table class='vindLeuk'>
					<tr>
						<td>
							<iframe src='http://www.facebook.com/plugins/like.php?href=http://localhost:8080/SoftwareProjectJava/specs?ID=${product.EAN_UCC_13}&amp;locale=nl_NL&amp;send=false&amp;layout=box_count&amp;width=95&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=90' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:95px; height:65px;' allowTransparency='true'></iframe>
						</td>
						<td>
						<div class='kerenGekocht'>
						<c:set var='counter' value='0' />
						<c:forEach items='${sales}' var='sale'>
						<c:if test='${sale.EAN_UCC_13 == product.EAN_UCC_13}'>
						<c:set var='counter' value='${counter + 1}' />
						</c:if>
						</c:forEach>
						<c:choose>
							<c:when test='${counter == 0}'>Nog niemand heeft<br/>deze notebook in bezit.
							</c:when>
							<c:when test='${counter == 1}'>${counter} persoon heeft<br/>deze notebook gekocht.
							</c:when>
							<c:otherwise>${counter} personen hebben<br/>deze notebook gekocht.
							</c:otherwise>
						</c:choose>
						</div>
						</td>
					</tr>
				</table>
			</div>
		</td>
		<td class='td60'>
			<form action='productCheckup' method='post'>
				<div class='center'>
					<div class='schikkingKnoppen'>
					<button class='submit' type='submit' name='btnSpecs' value='${product.EAN_UCC_13}'>Uitgebreide specificaties</button>
					<button class='submit' type='submit' name='btnStores' value='${product.EAN_UCC_13}'>Verkooppunten</button>
					<button class='submit' type='submit' name='btnCompare' value='${product.EAN_UCC_13}'>Vergelijkbare producten</button>
					</div>
				</div>
			</form>
		</td>
	</tr>
</table>
<c:forEach items='${offers}' var='offer'>
	<c:if test='${product.EAN_UCC_13 == offer.EAN_UCC_13}'>
	<div class='groepTableFix'>
		<table class='productTable'>
			<tr>
				<td class='tdGroepsTitel' colspan='3'>
					<span class='tdGroepsTitel'>
						Deze notebook is als groepsaankoop beschikbaar!
					</span>
				</td>
			</tr>
			<tr>
				<td class='tdPrijs'>
					<span class='highlight'>${product.price}</span> euro
				</td>
				<td class='tdKorting'>
					<span class='highlight'>${offer.discount}%</span> groepskorting
				</td>
				<td class='tdButton' rowspan='4'>
					<form action='productCheckup' method='post'>
						<div  class='center'>
							<div class='winkelwagenFoto'>
								<img src='resources/images/shopcartapply.png' alt='' />
							</div>
							<button class='submit' type='submit' name='btnWinkelwagen' value='${product.EAN_UCC_13}'>Toevoegen aan winkelwagen</button>
						</div>
					</form>
				</td>
			</tr>
			<tr>
				<td class='tdExtraInfo' colspan='2'>
					Er moeten minstens <span class='highlight'>${offer.minParticipators}</span> inschrijvingen zijn.
				</td>
			</tr>
			<tr>
				<td class='tdExtraInfo' colspan='2'>
					<c:set var='counter' value='0'/>
					<c:forEach items="${personsInOffer}" var="PersonInOffer">
						<c:if test="${PersonInOffer.offer_id == offer.offer_id}">
							<c:set var="counter" value="${counter + PersonInOffer.amount }" />
						</c:if>
					</c:forEach>
					<c:choose>
						<c:when test='${counter == 0}'>
							Tot nu toe zijn er nog geen inschrijvingen.
						</c:when>
						<c:when test='${counter == 1}'>
							Tot nu toe is er al <span class='highlight'><c:out value='${counter}'></c:out> </span> inschrijving.
						</c:when>
						<c:otherwise>
							Tot nu toe zijn er al <span class='highlight'><c:out value='${counter}'></c:out> </span> inschrijvingen.
						</c:otherwise>
					</c:choose>
				</td>
			</tr>
			<tr>
				<td class='tdExtraInfo' colspan='2'>
					Aanbod geldig tot en met <span class='highlight'>${offer.availabilityEnd}</span>.
				</td>
			</tr>
		</table>
	</div>
	</c:if>
</c:forEach>
<br/>
<br/>
</c:forEach>